using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;

public class ItemDrager : MonoBehaviour
{
    public Image m_Preview;
    public Item m_Item;

    public static ItemDrager Create(Item item = null)
    {
        GameObject theNew = new GameObject();
        var canvas = Utils.GetCanvas();
        if(canvas)
        {
            theNew.transform.SetParent(canvas.transform);
            theNew.transform.SetSiblingIndex(canvas.transform.childCount);
        }
        var itemDrager = theNew.AddComponent<ItemDrager>();
        itemDrager.m_Preview= theNew.AddComponent<Image>();
        itemDrager.m_Preview.raycastTarget = false;
        if (item != null)
            itemDrager.m_Item = item;
        return itemDrager;
    }
    private void Awake()
    {
    }
    void Start()
    {
        
    }

    void Update()
    {
        
    }
    public void Init(Item item)
    {
        if(item == null)
        {
            return;
        }
        m_Item = item;
        var sprite = ResourcesManager.Instance.GetItemSprite(item);
        if (m_Preview != null)
            m_Preview.sprite = sprite;
     }
}
